-- funcao de redesenho de cada ciclo de animacao
function redraw()
    local filename = "../webservice/eliminatorias1_jogos"
    file, err = io.open(filename, "r")
    if (err == nil) then
        canvas:attrFont('vera',26,'bold')
        local i = 0
        for line in file:lines() do
            print ("****" .. line)
            time1, value1, value2, time2, pen1, pen2 = string.match(line, "^([a-z-]*)[ ]*([0-9]*)[ ]*([0-9]*)[ ]*([a-z-]*)[ ]*([0-9]*)[ ]*([0-9]*)$")
            print ("****" .. time1, time2, value1, value2, pen1, pen2)
            if (time1 ~= nil) then
                local img1 = canvas:new(("../media/bandeiras-legendas/" .. time1 .. ".gif"))
                local img2 = canvas:new(("../media/bandeiras-legendas/" .. time2 .. ".gif"))
                if i < 4 then
                    canvas:compose(18, (29 + i*88), img1)
                    canvas:compose(18, (29 + 43 + i*88), img2)
                    canvas:drawText(133, (31 + i*88), value1)
                    canvas:drawText(133, (31 + 43 + i*88), value2)
                elseif i > 3 and i < 6 then
                    canvas:compose(172, (47 + (i - 4)*175), img1)
                    canvas:compose(172, (47 + 89 + (i - 4)*175), img2)
                    canvas:drawText(288, (47 + (i - 4)*175), value1)
                    canvas:drawText(288, (47 + 89 + (i - 4)*175), value2)
                elseif i < 7 then
                    canvas:compose(330, 136, img1)
                    canvas:compose(330, 222, img2)
                    canvas:drawText(449, 136, value1)
                    canvas:drawText(449, 222, value2)
                else
                    canvas:compose(482, 178, img1)
                    canvas:drawText(602, 178, value1)
                end                    
            end
            i = i + 1
            canvas:flush()
        end
        file:close()
    else 
        print (err)
    end
end

redraw()